<?php
/**
 * QQAS - share your knowledge to the world!
 *
 * @author		xiaochong0302 <xiaochong0302@gmail.com>
 * @copyright	Copyright (c) 2011, Koogua Studio.
 * @license		http://www.qqas.org/user_guide/license.html
 * @link		http://www.qqas.org
 * @since		Version 1.0
 * @filesource
 */


class ConfigModel extends Model
{

	//转化查询出的二维数组为一维数组
	public function getConfigs()
	{
		$configs = array();
		$order = array('name' => 'asc');
		$results = $this->order($order)->select();
		if(is_array($results) && !empty($results))
		{
			foreach ($results as $key => $val)
			{
				$configs[$val['name']] = $val['value'];
			}
		}
		return $configs;
	}


	//保存更新设置
	public function updateConfigs($data=array())
	{
		if (is_array($data) && !empty($data))
		{
			foreach ($data as $key => $value)
			{
				$this->where("name='{$key}'")->setField('value', $value);
			}
		}
		$configs = $this->getConfigs();
		F('cache_site_configs', $configs);
	}


	//缓存设置
	public function cacheConfigs()
	{
    	$configs = $this->getConfigs();
    	F('cache_site_configs', $configs);
	}

}

/* End of file ConfigModel.class.php */
/* Location: ./App/Lib/Model/ConfigModel.class.php */